package edu.uta.cfl.engine.constraint;

import choco.Choco;
import choco.kernel.model.constraints.Constraint;
import choco.kernel.model.variables.Variable;
import choco.kernel.model.variables.integer.IntegerExpressionVariable;
import edu.uta.cfl.util.Constants;

/*
 * This class is used for type checking in constraint parser.
 */
public class TypeInfo {
	// ADDED by Lei
	private String text;
	private Constraint constraint;
	private IntegerExpressionVariable variable;
	private Object obj;

	int type;

	public void setType(int type) {
		this.type = type;
	}

	public int getType() {
		return type;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	Constraint getConstraint() {
		if (constraint == null && variable != null
				&& type == Constants.TYPE_BOOL) {
			constraint = Choco.eq(variable, 1);// this is important to promote a
												// boolean variable to a
												// constraint!!
		}
		return constraint;
	}

	void setConstraint(Constraint constraint) {
		this.constraint = constraint;
	}

	IntegerExpressionVariable getVariable() {
		return variable;
	}

	void setVariable(IntegerExpressionVariable variable) {
		this.variable = variable;
	}

	Object getObj() {
		if (constraint != null)
			return constraint;
		return variable;
	}

	void setObj(Object obj) {
		this.obj = obj;
		if (obj instanceof Constraint)
			constraint = (Constraint) obj;
		else if (obj instanceof Variable)
			variable = (IntegerExpressionVariable) obj;
	}
}
